// 客户模糊查询
import React from 'react';
import { Select, Spin } from 'antd';
import { connect } from 'dva';

const { Option } = Select;

@connect(({ injuryware: { injuryList }, loading }) => ({
  injuryList,
  loading: loading.effects['injuryware/fetchInjuryList'],
}))
class InjuryList extends React.Component {
  // constructor(props) {
  //   super(props);
  // }

  // 获取大库列表
  search = value => {
    const { dispatch } = this.props;
    if (value.trim().length) {
      dispatch({
        type: 'injuryware/fetchInjuryList',
        payload: { injSecAccoName: value.trim() },
      });
    }
  };

  render() {
    const { injuryList = [], loading, getData = () => {} } = this.props;
    return (
      <Select
        placeholder="请输入关键字检索"
        {...this.props}
        showSearch
        optionFilterProp="children"
        showArrow={false}
        onSearch={this.search}
        onSelect={(value, options) => getData(value, options)}
        notFoundContent={loading ? <Spin size="small" /> : null}
      >
        {injuryList.map(item => (
          <Option key={item.injSecAccoId}>{item.injSecAccoName}</Option>
        ))}
      </Select>
    );
  }
}
export default InjuryList;
